import { GatewayPart } from "@/droplet-bus/core.define";
import { ENUM_APP, ENUM_APP_PORT_REST, ENUM_APP_PORT_TCP } from "@/droplet-bus/core.define";
import { Book } from "./schema.book";
import { Sortable } from "~/search.match";

export const app_gateway: GatewayPart = {
  app: ENUM_APP.POND_BOOK,
  port_tcp: ENUM_APP_PORT_TCP.POND_BOOK,
  port_rest: ENUM_APP_PORT_REST.POND_BOOK,
};

export type BookSortable = { type: Book["type"]; direction: Book["direction"]; sorter: Sortable };
export type BookQuery = { type: Book["type"]; direction: Book["direction"] };
export type BookQueryCache = { stats: (BookQuery & { timeUpdated: number; total: number })[] };

/** 账簿记录的类型 🔴资产🟢负债🔴🔵资产过渡/期末余额在借方🔵🟢负债过渡/期末余额在贷方
 * @line -------------
 * @ToB 签立销售合同 🔴🔵应收账款（合同）100w 🔵🟢主营业务收入（合同）100w
 * @line -------------
 * @ToB 收到货款 🔴基本存款账户 100w 🔵🟢应收账款（待认领）100w
 * @ToB 确认货款 🔵🟢应收账款（待认领）100w 🔴🔵应收账款（合同）100w
 * @line -------------
 * @ToB 开出发票 🔴🔵主营业务收入（未审核）100w 🟢主营业务收入（已开发票）87w 🟢应交税费 13w
 * @ToB 收到发票 🔵🟢主营业务收入（合同）100w 🔴🔵主营业务收入（未审核）100w
 * @line -------------
 * @ToB 签立退款销售合同 🔵🟢主营业务收入（退款合同）100w 🔴🔵应收账款（退款合同）100w
 * @line -------------
 * @ToB 实际退款 🔵🟢应收账款（退款待认领）100w 🔴基本存款账户 100w
 * @ToB 确认货款 🔴🔵应收账款（退款合同）100w 🔵🟢应收账款（退款待认领）100w
 * @line -------------
 * @ToB 签立采购合同 🔴🔵主营业务成本（合同）60w 🔵🟢应付账款（合同）60w
 * @line -------------
 * @ToB 付货款 🔴🔵应付账款（未审核）60w 🔴基本存款账户 60w
 * @ToB 确认货款 🔵🟢应付账款（合同）60w 🔴🔵应付账款（未审核）60w
 * @line -------------
 * @ToB 收到发票 🔴主营业务成本（收到发票）52w 🟢应交税费 8w 🔵🟢主营业务成本（未审核）60w
 * @ToB 确认发票 🔵🟢主营业务成本（未审核）60w 🔴🔵主营业务成本（合同）60w
 */
export enum ENUM_BOOK_TYPE {
  NONE = -1,

  /** 🔴基本存款账户 */
  CUN_KUAN_ZHANG_HU = 1002101,

  /** 🟢应交税费 */
  YING_JIAO_SHUI_FEI = 2221101,

  // ================================================================================
  // ================================================================================
  // ================================================================================

  /** 🔴🔵应收账款（合同） */
  YING_SHOU_ZHANG_KUAN_ORDER = 1122101,

  /** 🔵🟢应收账款（待认领）*/
  YING_SHOU_ZHANG_KUAN_CHECKING = 1122102,

  /** 🔴🔵应收账款（退款合同） */
  YING_SHOU_ZHANG_KUAN_RETURN_ORDER = 1122103,

  /** 🔵🟢应收账款（退款待认领）*/
  YING_SHOU_ZHANG_KUAN_RETURN_CHECKING = 1122104,

  /** 🔵🟢应付账款（合同） */
  YING_FU_ZHANG_KUAN_ORDER = 2202101,

  /** 🔴🔵应付账款（未审核）*/
  YING_FU_ZHANG_KUAN_CHECKING = 2202102,

  // ================================================================================
  // ================================================================================
  // ================================================================================

  /** 🔵🟢主营业务收入（合同） */
  ZHU_YING_YE_WU_SHOU_RU_ORDER = 6001101,

  /** 🔴🔵主营业务收入（未审核）*/
  ZHU_YING_YE_WU_SHOU_RU_CHECKING = 6001102,

  /** 🟢主营业务收入（已开发票）*/
  ZHU_YING_YE_WU_SHOU_RU_TAX = 6001103,

  /** 🔵🟢主营业务收入（退款合同） */
  ZHU_YING_YE_WU_SHOU_RU_RETURN_ORDER = 6001104,

  /** 🔴🔵主营业务收入（退款未审核）*/
  ZHU_YING_YE_WU_SHOU_RU_RETURN_CHECKING = 6001105,

  /** 🔴🔵主营业务成本（合同） */
  ZHU_YING_YE_WU_CHENG_BEN_ORDER = 6401101,

  /** 🔵🟢主营业务成本（未审核）*/
  ZHU_YING_YE_WU_CHENG_BEN_CHECKING = 6401102,

  /** 🔴主营业务成本（收到发票）*/
  ZHU_YING_YE_WU_CHENG_BEN_TAX = 6401103,
}

/** 账簿记录的借贷方向 */
export enum ENUM_BOOK_DIRECTION {
  NONE = -1,
  JIE = 1000,
  DAI = 2000,
}
